﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Sale
{
    public partial class BiaoShu : System.Web.UI.Page
    {
        protected void Button_GL_Click(object sender, EventArgs e)
        {
            Response.Redirect("BiaoShu_GL.aspx");
        }

        protected void Button_MX_Click(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            Response.Redirect("XunJiaGuanLi.aspx?BiaoShuID=" + b.CommandArgument + "&n=" + b.CommandName);
        }
        //继续创建
        //protected void Button_New_Click(object sender, EventArgs e)
        //{
        //    Response.Redirect("BiaoShu.aspx");
        //}

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            string mc = this.MingCheng.Text.Replace("'", "").Trim();
            if (mc == "")
            {
                this.Message.Text = "·请输入计划名称";
                return;
            }
            DateTime d1;
            if (!DateTime.TryParse(RiQi1.Text, out d1))
            {
                this.Message.Text = "·请正确输入日期";
                return;
            }
            //else if (d1 > d2)
            //{
            //    this.Message.Text = "·截止日期需在起始日期之后";
            //}
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "BiaoShu_New";
            Cmd.CommandType = CommandType.StoredProcedure;
            Cmd.Parameters.Add(new SqlParameter("@标书名称", SqlDbType.NVarChar, 40, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, mc));
            Cmd.Parameters.Add(new SqlParameter("@投标日期", SqlDbType.DateTime, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Proposed, d1));
            Cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4, ParameterDirection.Output, true, 0, 0, "", DataRowVersion.Proposed, null));
            if (Cmd.ExecuteNonQuery() > 0)
            {
                this.Button_MX.CommandArgument = ((int)Cmd.Parameters["@ID"].Value).ToString();
                this.Button_MX.CommandName = mc;
                this.Panel1.Visible = true;
                this.Panel2.Visible = false;
                // this.Message.Text = "中标书创建成功";
                Button b = (Button)sender;
                Response.Redirect("XunJiaGuanLi.aspx?BiaoShuID=" + ((int)Cmd.Parameters["@ID"].Value).ToString() + "&BiaoShuMing=" + mc);
            }
            else
            {
                this.Message.Text = "中标书创建失败!";
                return;               
            }
            Cmd.Dispose();
            Conn.Close();
            Conn.Dispose();
        }

        protected void Button_Cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("BiaoShu_GL.aspx");
        }
    }
}
